(function(window) {
    var Index_getKnowledgeCtrl = {
        data: {},
        init: function(data) {
            //alert(1);
            //$(".toolbar").hide();	
            this.bindEven();
            this.timepp();
            //data['timepp']=setInterval(Index_getKnowledgeCtrl.timepp(),1000);
        },
        bindEven: function() {
            var bindings = [{
                // element:document,
                element: '#signBtn',
                event: hiApp.device.click,
                handler: this.sign
            }];
            bindEvents(bindings);
        },

        timepp: function() {
            var sec = Number($("#signBtnBefore").attr('sec'));
            if (!sec > 0) {
            	$("#signBtn").unbind(hiApp.device.click);
                return;
            }
            Index_getKnowledgeCtrl.data['timepp'] = setInterval(function() {
                var now = Number($("#signBtnBefore span").text());
                if (now > 0) {
                    now--;
                    $("#signBtnBefore span").text(now);

                } else {
                    $("#signBtnBefore").hide();
                    $("#signBtn").show();
                    clearInterval(Index_getKnowledgeCtrl.data['timepp']);
                }
            }, 1000);



        },
        sign: function() {
            $(this).unbind(hiApp.device.click);
            $.getJSON(base_url + "/Index/sign", {
                knowledge: $("#KnowledgeVaule").val(),
            }, function(data) {
                if (data.error > 0) {
                    Index_getKnowledgeCtrl.bindEven();
                    hiApp.alert(data.msg);
                } else {
                    hiApp.alert("打卡成功");
                    $("#signBtn").text("已打卡");
                }
            })

        },
        afterShow: function() {
            $(".toolbar").hide();
        },
        afterHide: function() {
            $(".toolbar").hide();
        },

    };

    window.BoxEdu_Index_getKnowledgeCtrl = Index_getKnowledgeCtrl;

})(window);
